package com.cuitrip.business.tripservice.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.cuitrip.component.item.ItemLayout;
import com.cuitrip.component.para.ParaListView;
import com.cuitrip.component.para.model.Para;
import com.cuitrip.service.R;
import com.lab.utils.ArrayUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 编辑并显示基本详情layout
 * Created by ak
 */
public class EditDetailLayout<T extends Para> extends LinearLayout {

    private Context mContext;

    @Bind(R.id.label)
    protected ItemLayout mLabel;

    @Bind(R.id.para_list)
    protected ParaListView paraListView;

    private List<Para> mParaList = new ArrayList<Para>();

    public EditDetailLayout(Context context) {
        super(context);
        initInternal(context);
    }

    public EditDetailLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        initInternal(context);
    }

    public EditDetailLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initInternal(context);
    }

    private void initInternal(Context context) {
        mContext = context;
        LayoutInflater.from(mContext).inflate(R.layout.edit_show_detail_layout, this);
        ButterKnife.bind(this);
        initListener();
    }

    public void setParaList(List<Para> paraList) {
        mParaList.clear();
        if (!ArrayUtil.isNullOrEmpty(paraList)) {
            mParaList.addAll(paraList);
        }
        paraListView.setTextColor(R.color.ct_black);
        paraListView.setParas(mParaList);
        if (ArrayUtil.isNullOrEmpty(mParaList)){
            mLabel.setBottomLineStyle(ItemLayout.FULL);
        }else{
            mLabel.setBottomLineStyle(ItemLayout.CONTENT);
        }
    }


    public void setTitle(CharSequence text) {
        mLabel.setleftText(text);
    }

    private NavigateAction navigateAction;

    public void setNavigateAction(NavigateAction navigateAction) {
        this.navigateAction = navigateAction;
    }

    public interface NavigateAction {
        public void navigate();
    }

    public void initListener() {
        mLabel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (navigateAction != null) {
                    navigateAction.navigate();
                }
            }
        });
    }

    public void showRightHint(boolean isShow) {
        mLabel.setShowRightIcon(isShow);
    }

}
